home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / oleo-1_4.lha / oleo-1.4 / cmd.h < prev    next >
C/C++ Source or Header  |  1993-05-21  |  11KB  |  404 lines

  1. #ifndef CMDH
  2. #define CMDH
  3.  
  4. /*    Copyright (C) 1992, 1993 Free Software Foundation, Inc.
  5.  
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with this software; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19. /*  t. lord    Wed Oct 14 12:01:37 1992    */
  20.  
  21. /*
  22.  * This file explains the generic interface to interactive functions.
  23.  * This covers how C functions are made available to the user, how
  24.  * keymaps are structured.  This also describes the variables that
  25.  * hold the user's interaction state .
  26.  */
  27. #include "global.h"
  28. #include "obstack.h"
  29. #include "line.h"
  30. #include "key.h"
  31. #include "args.h"
  32. #include "funcs.h"
  33. #include "info.h"
  34.  
  35.  
  36.  
  37. #ifdef __STDC__
  38. typedef void (*alarm_fn)(void);
  39. #else
  40. typedef void (*alarm_fn)();
  41. #endif
  42.  
  43. struct alarm_entry
  44. {
  45.   alarm_fn fn;
  46.   int freq;            /* in seconds. */
  47.   time_t last_time;
  48. };
  49.  
  50.  
  51. extern struct alarm_entry alarm_table[];
  52.  
  53. #define cell_timer_seconds  (alarm_table[0].freq)
  54.  
  55.  
  56.  
  57.  
  58. /* Fields prefixed by _ should normally be accessed via the macros
  59.  * defined further on. 
  60.  */
  61.  
  62. struct command_frame;
  63. struct macro;
  64.  
  65. struct input_stream
  66. {
  67.   /* The currently executing macro. */
  68.   struct macro *_rmac;
  69.  
  70.   unsigned char * _last_macro;        /* The last anonymous macro. */
  71.  
  72.   /* If a macro is being exectuted, arguments to a command
  73.    * are read from this string.
  74.    */
  75.   char *_func_arg;
  76.  
  77.   /* Call stack for macros. */
  78.   struct obstack _macro_stack;
  79.  
  80.   /* The macro being recorded, if any. */
  81.   unsigned char *_macro;
  82.   unsigned char *_macro_start;
  83.   unsigned int _macro_size;
  84.  
  85.   /* If this input stream was created only to execute a macro, 
  86.    * this will point to the input_stream it suspended.
  87.    * The purpose of this stack is to give command_loop the ability to
  88.    * execute exactly one macro and then return.
  89.    *
  90.    * Note that within an input stream there is another macro stack. 
  91.    * That stack is used internally to command_loop.
  92.    */
  93.   struct input_stream * prev_stream;
  94.  
  95.   int _pushed_back_char;
  96. };
  97.  
  98.  
  99. struct macro
  100. {
  101.   struct macro *mac_prev;
  102.   unsigned char *mac_exe;
  103.   CELLREF mac_row, mac_col;
  104.   struct rng mac_rng;
  105.  
  106.   int count;            /* Repeat count for this macro. */
  107.   unsigned char * mac_start;    /* Beginning the current cell's string (as */
  108.                 /* copied to the macro stack). */
  109. };
  110.  
  111. /* When a key is bound to a range, that range is stored here and 
  112.  * the CODE field of the binding is an index.  This is bogus.
  113.  * Variables should be used.
  114.  */
  115. extern int n_bound_macros;
  116. extern struct rng *bound_macros;
  117. extern int bound_macro_vec;
  118.  
  119.  
  120.  
  121. /* The pattern of interaction is:
  122.  *   the user selects an interactive function
  123.  *   a list of arguments to that function are assembled
  124.  *   the function is called
  125.  *
  126.  * This type is a union of the types that arguments to interactive
  127.  * functions can have.
  128.  */ 
  129. union command_arg_val
  130. {
  131.   char character;
  132.   FILE * fp;
  133.   int integer;
  134.   double floating;
  135.   struct key_sequence key;    /* Passed as (struct keyseq *). */
  136.   struct rng range;        /* Passed as (struct rng *). */
  137.   char * string;
  138. };
  139.  
  140.  
  141. #ifdef __STDC__
  142. typedef void (*direction_function) (int magic, int repeat);
  143. #else
  144. typedef void (*direction_function) ();
  145. #endif
  146.  
  147.  
  148. struct command_arg
  149. {
  150.   int do_prompt;        /* If true, the user gets to edit this. */
  151.   int is_set;            /* If true, a valid value is stored here. */
  152.   struct prompt_style * style;    /* The editting mode for this argument. */
  153.   char * arg_desc;        /* Pointer into FUNC_ARGS of CUR_CMD. */
  154.   char * prompt;        /* Unexpanded prompt */
  155.   char * expanded_prompt;
  156.  
  157.   struct info_buffer * prompt_info;/* Info that should be displayed while */
  158.                 /* prompting for this argument. */
  159.   int info_line;        /* First line visible in prompt_info */
  160.  
  161.   struct line text;        /* A buffer for the user to edit this value. */
  162.   int cursor;            /* cursor position of this buffer. */
  163.   int overwrite;        /* Is overwrite mode on? */
  164.  
  165.   /* For incremental commands. */
  166.   direction_function inc_cmd;
  167.  
  168.   /* For reading a character with timeout. */
  169.   int timeout_seconds;
  170.  
  171.   /* The value as it will be passed to the cmd function. */
  172.   union command_arg_val val;
  173. };
  174.  
  175. #define MAX_COMMAND_ARGS    10
  176.  
  177. /* These declarations make up the state of the command interpreter. */
  178.  
  179. struct command_frame 
  180. {
  181.   /* If `recursive' edits are enabled, there can be more than one of these. */
  182.   struct command_frame * next;
  183.   struct command_frame * prev;
  184.  
  185.   struct input_stream * input;
  186.   
  187.   /* The cell being editted (if any). */
  188.   CELLREF _setrow;
  189.   CELLREF _setcol;
  190.   
  191.   /* The current cell and the mark. */
  192.   CELLREF _curow;
  193.   CELLREF _cucol;
  194.   CELLREF _mkrow;
  195.   CELLREF _mkcol;
  196.  
  197.   /* What passes for a window configuration, for now. */
  198.   /* 
  199.    * When the input area is active, it appears to be just another window,
  200.    * reachable by other-window.  These values must be maintained by any
  201.    * implementation of io_get_line.
  202.    */
  203.   int _window_after_input;    /* Id of the window prior to the input area. */
  204.   int _input_active;    /* Bool: is the input area selected? */
  205.  
  206.   
  207.   /* The current top level keymap. */
  208.   int top_keymap;
  209.   
  210.   /* Current position in the keymaps. */
  211.   int _cur_keymap;
  212.  
  213.   int saved_cur_keymap;        /* used when building a prefix arg */
  214.   
  215.   /* The about-to-begin executing command (if any). */
  216.   struct cmd_func *_cur_cmd;
  217.   short _cur_vector;
  218.  
  219.   /* The last character processed .*/
  220.   int _cur_chr;
  221.  
  222.   /* The prefix argument */
  223.   int _how_many;
  224.   struct line _raw_prefix;
  225.  
  226.   /* This becomes true if the user is ever prompted for arguments
  227.    * for this frame.
  228.    */
  229.   int complex_to_user; 
  230.  
  231.   int _cmd_argc;
  232.   int _cur_arg;
  233.   struct cmd_func * cmd;
  234.  
  235.   /* The arguments to the current function. 
  236.    * This is used only if the current function prompts for arguments.
  237.    */
  238.   struct command_arg argv[MAX_COMMAND_ARGS];
  239. };
  240.  
  241. /* When a command is executing, this points to the frame it should operate
  242.  * on:
  243.  */
  244.  
  245. extern struct command_frame * the_cmd_frame;
  246. extern struct command_frame * running_frames;
  247.  
  248.  
  249. /* For most code, the structure of command loops and input streams
  250.  * is unimportant.  To that code, we make it appear that there is just
  251.  * a set of global variables.
  252.  */
  253.  
  254. #define setrow            the_cmd_frame->_setrow
  255. #define setcol            the_cmd_frame->_setcol
  256. #define curow            the_cmd_frame->_curow
  257. #define cucol            the_cmd_frame->_cucol
  258. #define mkrow            the_cmd_frame->_mkrow
  259. #define mkcol            the_cmd_frame->_mkcol
  260.  
  261. #define window_after_input    the_cmd_frame->_window_after_input
  262. #define input_active        the_cmd_frame->_input_active
  263.  
  264. #define cur_keymap        the_cmd_frame->_cur_keymap
  265. #define cur_cmd            the_cmd_frame->_cur_cmd
  266. #define cur_vector        the_cmd_frame->_cur_vector
  267. #define cur_chr            the_cmd_frame->_cur_chr
  268. #define cur_arg            the_cmd_frame->_cur_arg
  269. #define cmd_argc        the_cmd_frame->_cmd_argc
  270.  
  271. #define how_many        the_cmd_frame->_how_many
  272. #define raw_prefix        the_cmd_frame->_raw_prefix
  273.  
  274. #define cur_input        the_cmd_frame->input
  275. #define rmac            cur_input->_rmac
  276. #define pushed_back_char    cur_input->_pushed_back_char
  277. #define last_macro        cur_input->_last_macro
  278. #define macro_func_arg        cur_input->_func_arg
  279. #define macro_stack        cur_input->_macro_stack
  280. #define making_macro        cur_input->_macro
  281. #define making_macro_start    cur_input->_macro_start
  282. #define making_macro_size    cur_input->_macro_size
  283.  
  284. #define the_cmd_arg          the_cmd_frame->argv[cur_arg]
  285.  
  286.  
  287.  
  288. #ifdef FD_SET
  289.  
  290. #define SELECT_TYPE fd_set
  291. #define SELECT_SET_SIZE FD_SETSIZE
  292.  
  293. #else /* no FD_SET */
  294.  
  295. /* Define the macros to access a single-int bitmap of descriptors.  */
  296. #define SELECT_SET_SIZE 32
  297. #define SELECT_TYPE int
  298. #define FD_SET(n, p) (*(p) |= (1 << (n)))
  299. #define FD_CLR(n, p) (*(p) &= ~(1 << (n)))
  300. #define FD_ISSET(n, p) (*(p) & (1 << (n)))
  301. #define FD_ZERO(p) (*(p) = 0)
  302.  
  303. #endif /* no FD_SET */
  304.  
  305. /* The fd's that are selected on in the interact loop. */
  306. extern SELECT_TYPE read_fd_set;
  307. extern SELECT_TYPE exception_fd_set;
  308. extern SELECT_TYPE write_fd_set;
  309. extern SELECT_TYPE read_pending_fd_set; /* These are the output of select. */
  310. extern SELECT_TYPE exception_pending_fd_set;
  311. extern SELECT_TYPE write_pending_fd_set;
  312.  
  313. #ifdef __STDC__
  314. typedef void (*select_hook_fn) (int fd);
  315. #else
  316. typedef void (*select_hook_fn) ();
  317. #endif
  318.  
  319. struct select_hook
  320. {
  321.   select_hook_fn hook_fn;
  322.   void * jrandom;
  323. };
  324.  
  325. extern struct select_hook file_read_hooks[SELECT_SET_SIZE];
  326. extern struct select_hook file_exception_hooks[SELECT_SET_SIZE];
  327. extern struct select_hook file_write_hooks[SELECT_SET_SIZE];
  328.  
  329.  
  330.  
  331. #ifdef __STDC__
  332. extern void free_input_stream (struct input_stream * stream);
  333. extern void pop_input_stream (void);
  334. extern void start_entering_macro (void);
  335. extern void bound_macro (int num);
  336. extern void run_string_as_macro (char * macro);
  337. extern void call_last_kbd_macro (int count);
  338. extern void end_macro (void);
  339. extern void stop_entering_macro (void);
  340. extern void store_last_macro (struct rng * rng);
  341. extern int real_get_chr (void);
  342. extern void push_command_frame (struct rng * rng, char * first_line, int len);
  343. extern void remove_cmd_frame (struct command_frame * frame);
  344. extern void free_cmd_frame (struct command_frame * frame);
  345. extern void pop_unfinished_command (void);
  346. extern void recover_from_error (void);
  347. extern void exit_minibuffer (void);
  348. extern void setn_arg_text (struct command_arg * arg, char * text, int len);
  349. extern void init_arg_text (struct command_arg * arg, char * text);
  350. extern void set_default_arg (struct command_arg * arg, char * text, int len);
  351. extern void command_loop (int prefix);
  352. extern void execute_command (char *str);
  353. extern int get_chr (void);
  354. extern void display_error_msg (char * msg, int c);
  355. extern void pushback_keystroke (int c);
  356. extern void io_error_msg (char *str,...);
  357. extern void io_info_msg (char *str,...);
  358. extern char * expand_prompt (char * str);
  359. extern void set_info (char * name);
  360. extern void page_info_backwards (int rep);
  361. extern void page_info (int rep);
  362. extern void view_info (char * name, int ignore);
  363. extern void with_keymap (char * mapname);
  364. extern void one_cmd_with_keymap (char * mapname, struct key_sequence * keyseq);
  365.  
  366. #else
  367. extern void free_input_stream ();
  368. extern void pop_input_stream ();
  369. extern void start_entering_macro ();
  370. extern void bound_macro ();
  371. extern void run_string_as_macro ();
  372. extern void call_last_kbd_macro ();
  373. extern void end_macro ();
  374. extern void stop_entering_macro ();
  375. extern void store_last_macro ();
  376. extern int real_get_chr ();
  377. extern void push_command_frame ();
  378. extern void remove_cmd_frame ();
  379. extern void free_cmd_frame ();
  380. extern void pop_unfinished_command ();
  381. extern void recover_from_error ();
  382. extern void exit_minibuffer ();
  383. extern void setn_arg_text ();
  384. extern void init_arg_text ();
  385. extern void set_default_arg ();
  386. extern void command_loop ();
  387. extern void execute_command ();
  388. extern int get_chr ();
  389. extern void display_error_msg ();
  390. extern void pushback_keystroke ();
  391. extern void io_error_msg ();
  392. extern void io_info_msg ();
  393. extern char * expand_prompt ();
  394. extern void set_info ();
  395. extern void page_info_backwards ();
  396. extern void page_info ();
  397. extern void view_info ();
  398. extern void with_keymap ();
  399. extern void one_cmd_with_keymap ();
  400.  
  401. #endif
  402.  
  403. #endif
  404.